/*
gcc bansshcnf.c -o bansshcnf -lssl -lcrypto

 */

#include <stdio.h>
#include <stdlib.h>
#include <openssl/conf.h>
/* 
struct Conf_Buf
{
  char **key;
  char **value;
} ;

typedef struct Conf_Buf Conf_Buf;

static void handle_error(const char *file, int lineno, const char *msg)
{
  fprintf(stderr, "** %s:%i %s\n", file, lineno, msg);
  ERR_print_errors_fp(stderr);
}
#define int_error(msg)  handle_error(__FILE__, __LINE__, msg)
 

 

#define CONFFILE "/etc/banssh/banssh.cnf"
 
Conf_Buf * get_config_info(char *Params,char *Sec_Name)
{
  int                  i;
  long                 i_val, err = 0;
  char                 *key, *s_val;

  STACK_OF(CONF_VALUE) *sec;
  CONF_VALUE           *item;
  CONF                 *conf;
  
 
  conf = NCONF_new(NCONF_default(  ));

  Conf_Buf *cb=NULL;

  if (!NCONF_load(conf, CONFFILE, &err))
    {
      if (err == 0){
	int_error("Error opening configuration file");
        return cb;
      }
      else
        {
	  fprintf(stderr, "Error in %s on line %li\n", CONFFILE, err);
	  int_error("Errors parsing configuration file");
          return cb;
        }
    }

  if (!(key = NCONF_get_string(conf, Params, Sec_Name)))
    {
      fprintf(stderr, "Error finding \"%s\" in [%s]\n", Sec_Name, Params);
      int_error("Error finding string");
    }
  printf("Sec: %s, Key: %s, Val: %s\n", Params, Sec_Name, key);
  if (!(sec = NCONF_get_section(conf, key)))
    {
      fprintf(stderr, "Error finding [%s]\n", key);
      int_error("Error finding string");
    }
  for (i = 0;  i < sk_CONF_VALUE_num(sec);  i++)
    {
      item = sk_CONF_VALUE_value(sec, i);
      printf("Sec: %s, Key: %s, Val: %s\n",
	     item->section, item->name, item->value);
    }
 

  // Yeah, everything gets freed
  NCONF_free(conf);

  return 0;
}

int main(void) {

  get_config_info("Params","ServerSection");
  return 0;
}

*/
